package com.anolesoft.Planexecution.mapper;


import com.anolesoft.Planexecution.dto.MesBzzProcessDto;
import com.anolesoft.Planexecution.dto.StoragPlanDto;
import com.anolesoft.Planexecution.entity.MesBzzFcfhjhDo;
import com.anolesoft.Planexecution.entity.MesBzzOrderDo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StoragPlanMapper {
    @Select("select count(objuid)\n" +
            "  from stf_employee\n" +
            " where delete_flag = 0\n" +
            "   and eid = #{eid, jdbcType = VARCHAR}\n" +
            "   and factory_id = #{fcode, jdbcType = VARCHAR}")
    int queryEmpAll (@Param("eid") String eid,@Param("fcode")String fcode);
    @Select("select count(objuid)\n" +
            "  from stf_employee\n" +
            " where password2 = #{password2, jdbcType = VARCHAR}\n" +
            "   and factory_id = #{fcode, jdbcType = VARCHAR}\n" +
            "   and now_quarters like '%检验%'")
    int queryEmpAll2 (@Param("password2") String password2,@Param("fcode")String fcode);
    //查询
    List<StoragPlanDto> queryAll (StoragPlanDto storagPlanDto);

    //查询当前行
    @Select("select tuhao,jixing from MES_BZZ_FCFHJH where objuid = #{objuid}")
    List<MesBzzFcfhjhDo> selectRow (List<String> objuid);

    @Select("select f.state from MES_BZZ_FCFHJH f left join MES_BZZ_ORDER o on f.objuid = o.PLANUID where o.BARCODE = #{zzjltm, jdbcType=VARCHAR}")
    int queryState (String zzjltm);

    //删除
    int update (MesBzzOrderDo orderDo);
    // 删除之后修改封存防护计划状态为未开始
    @Update("update mes_bzz_fcfhjh t set t.state = 0 where t.objuid = (select planuid from mes_bzz_order where objuid = #{objuid})")
    int updateFcfhjh(MesBzzOrderDo orderDo);

    //生成封存签
    int insert (MesBzzOrderDo orderDo);

    /**
     * 插入打印单表
     * @param
     * @return
     */
    @Insert("insert into MES_SS_PRODUCT_PRINTFINFO(objuid,FABRECORDID,JIXING,TUHAO,NAME,FINFO,PGH,DW,CODE,D_TIME,CODE_USER,C_TYPE,FACTORY_ID,DB_SL,P_NUM,F_TIME)" +
            " values(sys_guid(),#{barCode},#{jixing},#{tuhao},#{mingcheng},#{sealingMethod},#{paigonghao},'暂无'," +
            " 'FCQBH' || to_char(sysdate, 'yyyymmdd') || lpad(seq_fcqbh_code.nextval, 4, 0),to_date(#{storageperiod},'yyyy-MM-dd'),#{fengcunuser},'封存标签',#{factory},#{dbnum},0,sysdate)")
    int insertprint(StoragPlanDto storagPlanDto);


    //质量反馈-弹出
    List<MesBzzProcessDto> quaryProcess (String objuid);

    //
    int processDefine (String objuid);

    //操作员检测
    int updateOperator (MesBzzProcessDto mesBzzProcessDto);

    List<MesBzzProcessDto> selectAll (MesBzzProcessDto mesBzzProcessDto);

    //班长检测
    int updateMonitorobjuid (MesBzzProcessDto mesBzzProcessDto);

    //检验员检测
    int updateJianyanyuan (MesBzzProcessDto mesBzzProcessDto);


    void updateState(MesBzzProcessDto mesBzzProcessDto);

    List<StoragPlanDto> queryRow(List<String> objuids);

    /**
     * 存入产量报告表
     */
    int insertClbg();
    /**
     * 第一个操作者扫描存入开工日期
     */
    @Update("UPDATE MES_BZZ_ORDER SET commencementdate = SYSDATE WHERE OBJUID = #{objuid}")
    int kgsj(String objuid);
    /**
     * 最后一个检验员扫描存入完工日期
     */
    @Update("UPDATE MES_BZZ_ORDER SET completiondate = SYSDATE WHERE OBJUID = #{objuid}")
    int wgsj(String objuid);
}
